package servlet.sys;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdbc.DBUtils;

@WebServlet("/Register")
public class Register extends HttpServlet {
	private static final long serialVersionUID = 1L;

	

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connection connection = DBUtils.getConn();

		try {
			
			String user =request.getParameter("passwordsignup");
			user = new String(user.getBytes("iso-8859-1"),"utf-8");
			
			String  password = request.getParameter("passwordsignup_confirm");
			
			password =  new String(password.getBytes("iso-8859-1"),"utf-8");
			
			PreparedStatement ps = connection.prepareStatement(" insert into user(name,pasword) values(?,?)");
			ps.setString(1, user);
			ps.setString(2, password);
			ps.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("index.html");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
